<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
</script>
<div class="app">
    <section class="layout">
        <section class="main-content col-lg-12" id="bloodInpDetailDiv">
            <div class="content-wrap">
                <div class="wrapper" style="bottom: 50px;">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/blood/bloodImport/index')">入库处理</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <form:form id="searchForm" modelAttribute="bloodInpDetail"
                                                   onsubmit="return loadDivForm('mainCenterDiv','searchForm','${ctx}/blood/bloodInpDetail/index');"
                                                   method="post" class="form-inline">
                                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
                                            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />

                                            <div class="form-group">
                                                <label class=" control-label">入库单号：</label>
                                                <input class="form-control" id="inpNo" htmlEscape="false" type="text" readonly />
                                            </div>
                                            <div class="form-group">
                                                <label class=" control-label">入库时间：</label>
                                                <input name="createDate" id="createDate" htmlEscape="false" class="form-control Wdate" data-parsley-required="true" readonly />
                                            </div>
                                            <div class="form-group">
                                                <label class=" control-label">血液来源：</label>
                                                <select class="form-control" id="bloodSource"></select>
                                            </div>
                                            <div class="form-group">
                                                <input id="btnSubmit" class="btn btn-primary" type="button" onclick="saveListForm()" value="保存" />
                                                <input id="addBlood" class="btn btn-primary" type="button" value="添加" onclick="addInpItem()" />
                                            </div>
                                        </form:form>
                                    </div>
                                </div>
                                <form id="saveListForm" action="${ctx}/blood/bloodImport/save" method="post" class="form-inline">
                                    <table id="contentTable" class="table table-bordered table-striped mg-t datatable">
                                        <thead>
                                        <tr>
                                            <th hidden>jsonText</th>
                                            <th hidden>ID</th>
                                            <th hidden>血液来源</th>
                                            <th hidden>入库单号</th>
                                            <th>血袋号</th>
                                            <th hidden>血型代码</th>
                                            <th>血型</th>
                                            <th hidden>RH代码</th>
                                            <th>RH</th>
                                            <th hidden>血液成分ID</th>
                                            <th>血液成分</th>
                                            <th>储血量</th>
                                            <th hidden>单位</th>
                                            <th>单位</th>
                                            <th>采血日期</th>
                                            <th>有效期</th>
                                            <th>献血者</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${page.list}" var="bloodInpDetail" varStatus="idx">
                                        <tr xia="${idx.index}">
                                            <td hidden>${bloodInpDetail.id}<input type="hidden" id="id${idx.index}" name="detailList[${idx.index}].id" value="${bloodInpDetail.id}" /></td>
                                            <td hidden> ${bloodInpDetail.bloodInpMaster.bloodSource}<input type="hidden" id="detailList.bloodInpMaster.bloodSource${idx.index}"
                                                                                                           name="detailList[${idx.index}].bloodInpMaster.bloodSource"
                                                                                                           value="${bloodInpDetail.bloodInpMaster.bloodSource}" /></td>
                                            <td hidden> ${bloodInpDetail.bloodInpMaster.inpNo}<input type="hidden" id="detailList.bloodInpMaster.inpNo${idx.index}"
                                                                                                     name="detailList[${idx.index}].bloodInpMaster.inpNo"
                                                                                                     value="${bloodInpDetail.bloodInpMaster.inpNo}" /></td>
                                            <td> ${bloodInpDetail.bloodId}<input type="hidden" name="detailList[${idx.index}].bloodId" value="${bloodInpDetail.bloodId}" /></td>
                                            <td hidden> ${bloodInpDetail.patBloodGroupCode}<input type="hidden" name="detailList[${idx.index}].patBloodGroupCode"
                                                                                                  value="${bloodInpDetail.patBloodGroupCode}" /></td>
                                            <td> ${bloodInpDetail.patBloodGroup}<input type="hidden" name="detailList[${idx.index}].patBloodGroup" value="${bloodInpDetail.patBloodGroup}" /></td>
                                            <td hidden> ${bloodInpDetail.rhCode}<input type="hidden" name="detailList[${idx.index}].rhCode" value="${bloodInpDetail.rhCode}" /></td>
                                            <td> ${bloodInpDetail.rh}<input type="hidden" name="detailList[${idx.index}].rh" value="${bloodInpDetail.rh}" /></td>
                                            <td hidden> ${bloodInpDetail.componentId}<input type="hidden" name="detailList[${idx.index}].componentId" value="${bloodInpDetail.componentId}" /></td>
                                            <td> ${bloodInpDetail.bloodComponentName}<input type="hidden" name="detailList[${idx.index}].bloodComponentName"
                                                                                            value="${bloodInpDetail.bloodComponentName}" /></td>
                                            <td> ${bloodInpDetail.bloodCapacity}<input type="hidden" name="detailList[${idx.index}].bloodCapacity" value="${bloodInpDetail.bloodCapacity}" /></td>
                                            <td hidden> ${bloodInpDetail.units}<input type="hidden" name="detailList[${idx.index}].units" value="${bloodInpDetail.units}" /></td>
                                            <td> ${bloodInpDetail.unitsName}<input type="hidden" name="detailList[${idx.index}].unitsName" value="${bloodInpDetail.unitsName}" /></td>
                                            <td> ${bloodInpDetail.bloodGatherDate}<input type="hidden" name="detailList[${idx.index}].bloodGatherDate" value="${bloodInpDetail.bloodGatherDate}" /></td>
                                            <td> ${bloodInpDetail.invalDate}<input type="hidden" name="detailList[${idx.index}].invalDate" value="${bloodInpDetail.invalDate}" /></td>
                                            <td> ${bloodInpDetail.bloodDonorName}<input type="hidden" name="detailList[${idx.index}].bloodDonorName" value="${bloodInpDetail.bloodDonorName}" /></td>
                                            <td>
                                                <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/blood/bloodImport/form?id=${bloodInpDetail.bloodInpMaster.inpNo}')" class="btn btn-success btn-xs">修改</a>
                                                <a href="#" class="applyBt btn btn-danger btn-xs"
                                                   onclick="confirmExtend('确认要删除该数据吗？',function(){delLoad('mainCenterDiv','${ctx}/blood/bloodImport/delete?id=${bloodInpDetail.id}','${ctx}/sys/dict/index')})">删除</a>
                                            </td>
                                        </tr>
                                        </c:forEach>
                                    </table>
                                </form>
                                <div class="pagination">${page}</div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
        <%--右侧药品出库明细列表--%>
        <section class="main-content col-lg-4" style="display: none" id="bloodImportRightDiv">
            <div class="content-wrap" id="rigthCenterDiv">
            </div>
        </section>
    </section>
</div>
<script type="text/javascript">
    //设置入库日期为当前时间,不能编辑
    var date = new Date();
    var nowMonth = "";
    if (date.getMonth() + 1 <= 9) {
        nowMonth = "0" + (date.getMonth() + 1) + "";
    } else {
        nowMonth = (date.getMonth() + 1) + "";
    }
    var hours = "";
    if (date.getHours() < 10) {
        hours = "0" + date.getHours();
    } else {
        hours = date.getHours();
    }
    var minutes = "";
    if (date.getMinutes() < 10) {
        minutes = "0" + date.getMinutes();
    } else {
        minutes = date.getMinutes();
    }
    var seconds = "";
    if (date.getSeconds() < 10) {
        seconds = "0" + date.getSeconds();
    } else {
        seconds = date.getSeconds();
    }
    var now = date.getFullYear() + "-" + nowMonth + "-" + date.getDate() + " " + hours + ":" + minutes + ":" + seconds;
    $('#createDate').val(now);

    load();
    function load() {
        //入库单号赋值
        $.ajax({
            url: '${ctx}/blood/bloodImport/getMaxInpNo',
            type: 'get',
            contentType: 'application/json',
            async: true,
            success: function (data, textStatus, jqXHR) {
                var inpNo = '';
                if (null != data.data && data.data != '' && typeof(data.data) != 'undefined') {
                    inpNo = Number(data.data) + 1
                } else {
                    inpNo = 1
                }
                $('#inpNo').val(('000000' + inpNo).substr(-6));
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });

        //血液来源
        $.ajax({
            url: '${ctx}/blood/bloodImport/getBloodFromList',
            type: 'get',
            contentType: 'application/json',
            async: true,
            success: function (data, textStatus, jqXHR) {
                if (data.length > 0) {
                    $.each(data, function (index, item) {
                        $("#bloodSource").append("<option value='" + item.value + "'>" + item.label + "</option>");
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });
    }

    //保存
    function saveListForm() {
        $("#saveListForm").ajaxSubmit({
            success: function (data) {
                if (data.code == 'success') {
                    toastr.success(data.data);
                    loadDiv('mainCenterDiv', '${ctx}/blood/bloodImport/index');
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error(data.data);
            }
        });
    }

    //弹出右边增加血液明细
    function addInpItem() {
        $("#bloodInpDetailDiv").attr("class", "main-content col-lg-8");
        $("#bloodImportRightDiv").show('normal');
        return loadDiv('rigthCenterDiv', '${ctx}/blood/bloodImport/form');
    }

    //修改
    function updateList(btn) {
        var td = $(btn).parent().parent().children().eq(0).text();
        $("#bloodInpDetailDiv").attr("class", "main-content col-lg-8");
        $("#bloodImportRightDiv").show('normal');
        fillForm($("#inputForm"), td);
        $(btn).parent().parent().remove();
    }

    //删除
    function removeList(btn) {
        $(btn).parent().parent().remove();
    }
</script>